<!-- This page asks students for the university they earned their degree
     from. They can choose from a list of universities (provided based on
     the location they chose on the previous page). In the case that their
     university is not on the list, they can type in the name of their
     university in a text box. 
     
     Upon clicking submit, they are led to the Provide Degrees -- Choose
     Discipline Page. -->

<%@page import="support.*, java.util.*, java.sql.*, javax.sql.*" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> 
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> 
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Provide Degrees -- Choose Universities</title>
</head>
<body>

<CENTER>
<h1> Graduate School Application </h1>
<h2> Provide Degrees -- Choose University Page </h2>
</CENTER>


<b>First Name:</b> <bean:write name="studentsinfoform" property="first" />
<span style="padding-left:20px"><b>Middle Initial:</b> <bean:write name="studentsinfoform" property="middle" /></span>
<span style="padding-left:20px"><b>Last Name:</b>  <bean:write name="studentsinfoform" property="last" /> </span>
<p>
<b>Country of Citizenship:</b> <bean:write name="citizenshipform" property="citizen" /> <p>
<b>Country of Residence:</b> <bean:write name="residenceform" property="residence"/> <p>
<b>Country of Residency:</b> <bean:write name="residencyform" property="residency"/> <p>


<b>Address:</b><p>

	<logic:present name="addressform" property="street">
			<span style="padding-left:20px"><b>Street:</b> <bean:write name="addressform" property="street" /> <p></span>
	</logic:present>
	<logic:present name="addressform" property="city">
			<span style="padding-left:20px"><b>City:</b> <bean:write name="addressform" property="city" /> </span>
	</logic:present>	
	<logic:present name="addressform" property="lstate">
		<logic:notEqual  name="addressform" property="lstate" value="">
			<span style="padding-left:20px"><b>State:</b> <bean:write name="addressform" property="lstate" /> </span>
		</logic:notEqual>
	</logic:present>
	<logic:present name="addressform" property="zip">
		<logic:notEqual  name="addressform" property="zip" value="">
			<span style="padding-left:20px"><b>Zip Code:</b> <bean:write name="addressform" property="zip" /> </span>
		</logic:notEqual>
	</logic:present>
	
	<b>Phone Number:</b> (<bean:write name="addressform" property="areaCode" />) 
	                     (<bean:write name="addressform" property="pnumber" />) <p>

<logic:notEqual name="degreeform" property="count" value="first">
<logic:iterate id="degreeId" name="degreeform" property="degrees" >
==========================================================
<p><b>Location:</b> <bean:write name="degreeId" property="stuState"/></p>
<p><b>School:</b> <bean:write name="degreeId" property="school"/></p>
<p><b>Discipline of degree:</b> <bean:write name="degreeId" property="discp"/>
						 <bean:write name="degreeId" property="title"/></p>
<p><b>Degree earned in:</b> <bean:write name="degreeId" property="dmonth"/>
					 <bean:write name="degreeId" property="dyear"/></p>
<p><b>GPA: </b><bean:write name="degreeId" property="gpa"/></p>
<p><b>Transcript: </b><bean:write name="degreeId" property="fileName"/></p>
</logic:iterate>
</logic:notEqual>

<!-- End of displaying collected information. -->


<br><b>Current Degree being added:</b><p>

<b>Location degree earned from:</b> <bean:write name="degreeform" property="stuState" /> <p>

<!-- End of displaying collected information. -->

<br><b>Please specify the university you earned your degree from.</b> <p>
<b> **If you can't find your school in this list, please type the name
of your school in the text box at the bottom of this page.** </b> <p>

  <%

  
  support s = new support();   	
 	
 	String path2 = config.getServletContext().getRealPath("universities.txt");

  //getUniversities returns a vector of vectors where each vector is a tuple of <string, vector>
  //with the string being the name of the country/state and the vector being the list of universities there
  Vector universities = s.getUniversities(path2);
  String school;
  
  
  // print universities in 3-column format
    for (int i=0; i<universities.size(); i++){
      //each entry in the universities vector is a tuple with the first entry being the country/state
      //and the second entry being a vector of the universities as String's
      Vector tuple = (Vector)universities.get(i);
      String state = (String)tuple.get(0);
      if( state.equals(session.getAttribute("stuState")) ){
      		out.println("<br>"+"Universities in " +state+ ": " + "<br>");    
            	Vector u = (Vector)tuple.get(1);
            	int usize = u.size()/3;
            	int uleftover = u.size()%3;
            	
            	%>
            		<TABLE BORDER CELLSPACING=1 CELLPADDING=5>
            		<TR>
            	<%
            	for(int j=0; j<u.size()/3+1; j++){
            	      if(j == uleftover+usize){
            	       	 break;
            	       }
            		  
            	      %>
            	  	    <TD>
							<html:link action="/degreeUniv">
							<html:param name="school" value='<%= u.get(j).toString() %>'/> <%= u.get(j).toString() %>
							</html:link>
						</TD>
            	      <%
            		
            	      if(j+ uleftover+usize == uleftover+usize*2){
            	    	  break;
            	      }
            	  	    
            	  	  %>
            	  	    <TD>
							<html:link action="/degreeUniv">
							<html:param name="school" value='<%= u.get(j+ uleftover+usize).toString() %>'/> <%= u.get(j+ uleftover+usize).toString() %>
							</html:link>
						</TD>
            	      <% 
            	      
            	      if(j+ uleftover+usize*2 >= u.size()){
            	    	  break;
            	      }
            	  	    
            	  	  %>
            	        <TD>
							<html:link action="/degreeUniv">
							<html:param name="school" value='<%= u.get(j+ uleftover+usize*2).toString() %>'/> <%= u.get(j+ uleftover+usize*2).toString() %>
							</html:link>            	        
						</TD>
            	  	    </TR>
            	      <% 
      			}
            	    out.println("<br>");
            	    %>
            	    </TABLE>
            	    <%
      }
 %>
 
 
 <%
    } 
    
  %>

<br>
<html:form action="/degreeUniv">
Enter University: <html:text name = "degreeform" property="school" size="20" />
<input type="submit" value="Submit"/>
</html:form>


</body>
</html>